package com.example.crm.controller;

import org.springframework.web.bind.annotation.*;
import com.example.crm.entity.UserLogin;
import com.example.crm.service.UserLoginService;
import org.springframework.beans.factory.annotation.Autowired;

@RestController
@RequestMapping("/api/user")
@CrossOrigin(origins = "http://localhost:5173") // 允许前端端口5173跨域访问
public class UserLoginController {
    @Autowired
    private UserLoginService userLoginService;

    @PostMapping("/register")
    public UserLogin register(@RequestBody UserLogin user) {
        return userLoginService.register(user);
    }

    @PostMapping("/login")
    public UserLogin login(@RequestBody UserLogin user) {
        return userLoginService.login(user.getUsername(), user.getPassword());
    }
}